package com.wtgroup.demo.面试题.我的面试.九天科技;

import com.wtgroup.demo.mianshi.算法.二叉树.model.CompleteBinTree;
import com.wtgroup.demo.mianshi.算法.二叉树.model.Node;
import org.junit.Test;

import java.util.Arrays;
import java.util.List;

/**省钱快报, 三面问题
 * @author L&J
 * @version 0.0.0
 * @email liuhejun108@163.com
 * @date 2019/9/17 17:23
 */
public class 二叉树深度计算 {

    @Test
    public void fun(){
        List<Integer> list = Arrays.asList(1, 2, 3, 4, 5);
        CompleteBinTree tree = new CompleteBinTree(list);
        System.out.println(tree);

        System.out.println(getDepth(tree.getRoot()));
    }

    public int getDepth( Node node ) {
        int ld = 1, rd = 1;
        if ( node.getLeft() != null ) {
            ld += getDepth(node.getLeft());
        }
        if ( node.getRight() != null ) {
            rd += getDepth(node.getRight());
        }

        return Math.max(ld, rd);
    }

}
